package cn.tedu.boot.ers.service.impl;

import cn.tedu.boot.ers.entity.Dishes;
import cn.tedu.boot.ers.exception.ServiceException;
import cn.tedu.boot.ers.mapper.DishesMapper;
import cn.tedu.boot.ers.pojo.dto.DishesInsertDTO;
import cn.tedu.boot.ers.service.IDishesService;
import cn.tedu.boot.ers.web.State;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class DishesServiceImpl implements IDishesService {
    @Autowired
    DishesMapper dishesMapper;

    @Override
    public void insert(DishesInsertDTO dishesInsertDTO) {
        Dishes dishes = new Dishes();
        BeanUtils.copyProperties(dishesInsertDTO, dishes);
        int rows = dishesMapper.insert(dishes);
        if (rows != 1) {
            throw new ServiceException(State.ERR_INSERT, "服务器忙,请稍后再试");
        }
    }

    @Override
    public void delete(Long productId, Long userId) {
        int rows = dishesMapper.delete(productId, userId);
        if (rows != 1) {
            throw new ServiceException(State.ERR_INSERT, "服务器忙,请稍后再试");
        }
    }
}
